#include "header.h"

void print_to_file(timing* temp)
{	//Prints output to file
	FILE * output;
	timing times;
	int i=0;
	times = *temp;

	output = fopen("output.txt", "w");

	for(i=0;i<1000;i++)
			fprintf(output,"Line %4d : Min = %d, [327] = %d, Max = %d\n",
					i+1,quick_single_thread[i][0],quick_single_thread[i][326], quick_single_thread[i][999]);

	fprintf(output,"\nMerge sort of two rows - [1] = %d [986] = %d [1278] = %d\n",arraytable[0][0], arraytable[0][985], arraytable[0][1277]);

	fprintf(output,"\nSingle Merge [2] = %d [540987] = %d [899743] = %d\n",arraytable[1022][1],arraytable[1022][540986],arraytable[1022][899742]);
	fprintf(output,"Dual Merge   [2] = %d [540987] = %d [899743] = %d\n",merge2[1022][1],merge2[1022][540986],merge2[1022][899742]);
	fprintf(output,"Quad Merge   [2] = %d [540987] = %d [899743] = %d\n",merge4[1022][1],merge4[1022][540986],merge4[1022][899742]);
	fprintf(output,"Octa Merge   [2] = %d [540987] = %d [899743] = %d\n",merge8[1022][1],merge8[1022][540986],merge8[1022][899742]);
	fprintf(output,"16   Merge   [2] = %d [540987] = %d [899743] = %d\n\n",merge16[1022][1],merge16[1022][540986],merge16[1022][899742]);

	fprintf(output,"Average Time for Single Thread Quicksort is %lfs\n",times.quick_time);
	fprintf(output,"Average Time for Dual Thread Quicksort is %lfs\n",times.quick2_time);
	fprintf(output,"Average Time for Quad Thread Quicksort is %lfs\n",times.quick4_time);
	fprintf(output,"Average Time for Octa Thread Quicksort is %lfs\n",times.quick8_time);
	fprintf(output,"Average Time for 16   Thread Quicksort is %lfs\n\n",times.quick16_time);

	fprintf(output,"Average Time for Single Thread Mergesort is %lfs\n",times.merge_time);
	fprintf(output,"Average Time for Dual Thread Mergesort is %lfs\n",times.merge2_time);
	fprintf(output,"Average Time for Quad Thread Mergesort is %lfs\n",times.merge4_time);
	fprintf(output,"Average Time for Octa Thread Mergesort is %lfs\n",times.merge8_time);
	fprintf(output,"Average Time for 16   Thread Mergesort is %lfs\n",times.merge16_time);

	fclose(output);
}

void print_result(timing* temp)
{	//Prints output to console
	timing times;
	times = *temp;
	printf("Single Merge [2] = %d [540987] = %d [899743] = %d\n",arraytable[1022][1],arraytable[1022][540986],arraytable[1022][899742]);
	printf("Dual Merge   [2] = %d [540987] = %d [899743] = %d\n",merge2[1022][1],merge2[1022][540986],merge2[1022][899742]);
	printf("Quad Merge   [2] = %d [540987] = %d [899743] = %d\n",merge4[1022][1],merge4[1022][540986],merge4[1022][899742]);
	printf("Octa Merge   [2] = %d [540987] = %d [899743] = %d\n",merge8[1022][1],merge8[1022][540986],merge8[1022][899742]);
	printf("16   Merge   [2] = %d [540987] = %d [899743] = %d\n\n",merge16[1022][1],merge16[1022][540986],merge16[1022][899742]);

	printf("Average Time for Single Thread Quicksort is %lfs\n",times.quick_time);
	printf("Average Time for Dual Thread Quicksort is %lfs\n",times.quick2_time);
	printf("Average Time for Quad Thread Quicksort is %lfs\n",times.quick4_time);
	printf("Average Time for Octa Thread Quicksort is %lfs\n",times.quick8_time);
	printf("Average Time for 16   Thread Quicksort is %lfs\n\n",times.quick16_time);

	printf("Average Time for Single Thread Mergesort is %lfs\n",times.merge_time);
	printf("Average Time for Dual Thread Mergesort is %lfs\n",times.merge2_time);
	printf("Average Time for Quad Thread Mergesort is %lfs\n",times.merge4_time);
	printf("Average Time for Octa Thread Mergesort is %lfs\n",times.merge8_time);
	printf("Average Time for 16   Thread Mergesort is %lfs\n",times.merge16_time);
}
